package com.jn.exam.webSocket.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jn.exam.R;
import com.jn.exam.webSocket.entity.ExamStudentOnline;
import com.jn.exam.webSocket.entity.Student;
import com.jn.exam.webSocket.service.ExamStudentOnlineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 记录学生考试的上线还是下线动作 前端控制器
 * </p>
 *
 * @author 江南大学1033190417
 * @since 2022-03-08
 */
@RestController
@RequestMapping("/webSocket/exam-student-online")
@Api(description = "记录学生考试上下线动作")
public class ExamStudentOnlineController {

    @Autowired
    private ExamStudentOnlineService examStudentOnlineService;

    @ApiOperation("查询某场考试的所有学生上下线记录")
    @GetMapping("getAllStudentOnlineStatusOfExam")
    public R getAllStudentOnlineStatusOfExam(String examId){
        List<Map<String,Object>> list = examStudentOnlineService.listExamOnline(examId);
        return R.ok().data("list",list);
    }

    @ApiOperation("查询某场考试某个学生的上下线记录")
    @GetMapping("getStudentOnlineStatusOfExam")
    public R getStudentOnlineStatusOfExam(String examId,String studentId){
        QueryWrapper<ExamStudentOnline> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("gmt_create").eq("exam_id",examId).eq("student_id",studentId);
        List<ExamStudentOnline> list = examStudentOnlineService.list(wrapper);
        return R.ok().data("list",list);
    }


}

